<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let tree = {
        value: 1,
        children: [
          {
            value: 2,
            children: [
              {
                value: 4,
                children: [],
              },
              {
                value: 5,
                children: [],
              },
            ],
          },
          {
            value: 3,
            children: [
              {
                value: 6,
                children: [],
              },
              {
                value: 7,
                children: [],
              },
            ],
          },
        ],
      };

      // 输出所有的value值
      function fn(obj) {
        console.log(obj.value);
        if (obj?.children.length > 0) {
          obj?.children.forEach((item) => {
            fn(item);
          });
        }
      }

      fn(tree);
    </script>
  </body>
</html>
